package com.boang.exception;

/*
    @author:sa
    @date:2024/11/25 11:15
*/
public class ExceptionDemo03 {
    public static void main(String[] args) throws FuException {
        int[] ints = new int[3];
        try {
            m1(ints, -1);
        } catch (FuException e) {
            System.out.println("负数已处理");
//            throw new RuntimeException("运行时异常");
            e.printStackTrace();
            String message = e.getMessage();
            System.out.println(message);
        } catch (NullPointerException e) {
            System.out.println("空指针已处理");
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("下标越界已处理");
        }finally {
            System.out.println("ABC");
        }
        System.out.println("A");
    }

    public static void m1(int[] ints, int index) throws FuException {
        if (ints == null) {
            throw new NullPointerException("不能穿空对象");
        }
        if (index < 0) {
            throw new FuException("不能为负数");
        }
        if (index > ints.length) {
            throw new ArrayIndexOutOfBoundsException("下标越界，不能方法");
        }
        System.out.println(ints[index]);
    }
}